/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao.erp;

import cn.ekuma.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.datalogic.define.dao.UserInfoDAO;
import cn.ekuma.epos.db.table.erp.I_OrderState;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.bean.infobean.UserInfo;
import com.openbravo.bean.erp.Order;
import com.openbravo.bean.erp.OrderState;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

/**
 *
 * @author Administrator
 */
public class OrderStateDAO extends ModifiedLogDAO<OrderState> {

	UserInfoDAO userInfoDAO;
	
	public OrderStateDAO(I_Session s) {
        super(s);
    }
	
    public OrderStateDAO(I_Session s,UserInfoDAO userInfoDAO) {
        super(s);
        this.userInfoDAO=userInfoDAO;
    }

    @Override
    public TableDefinition getTable() {
        return new TableDefinition(s,
                  "ORDERSTATES",
                  new Field[]{
                       new Field(I_OrderState.ID,Datas.STRING,Formats.STRING),
                       new Field(I_OrderState.ORDERID,Datas.STRING,Formats.STRING,Order.class),
                       new Field(I_OrderState.PARENTID,Datas.STRING,Formats.STRING),
                       new Field(I_OrderState.CURDATE,Datas.TIMESTAMP,Formats.TIMESTAMP),
                       new Field(I_OrderState.STATE,Datas.STRING,Formats.STRING),
                       new Field(I_OrderState.MEMO,Datas.STRING,Formats.STRING),
                       new Field(I_OrderState.REFID,Datas.STRING,Formats.STRING),
                       new Field(I_OrderState.LASTMODIFIED,Datas.TIMESTAMP,Formats.TIMESTAMP)
                      },
                  new int[]{0});
    }

    @Override
    public void writeInsertValues(DataWrite dp, OrderState obj) throws BasicException {
        dp.setString(1,obj.getId());
        dp.setString(2,obj.getOrderID());
        dp.setString(3,obj.getM_User().getId());
        dp.setTimestamp(4,obj.getFireDate());
        dp.setString(5,obj.getState());
        dp.setString(6,obj.getMemo());
        dp.setString(7,obj.getRefId());
        dp.setTimestamp(8,obj.getLastModified());
    }

    public OrderState readValues(DataRead dr,OrderState p) throws BasicException {
        if(p==null)
        	p=new OrderState();
        p.setId(dr.getString(1));
        p.setOrderID(dr.getString(2));
        if(userInfoDAO!=null)
        	p.setM_User(userInfoDAO.loadPeopleByID(dr.getString(3)));
        else
           p.setM_User(new UserInfo(dr.getString(3)));
        p.setFireDate(dr.getTimestamp(4));
        p.setState(dr.getString(5));
        p.setMemo(dr.getString(6));
        p.setRefId(dr.getString(7));
        p.setLastModified(dr.getTimestamp(8));
        return p;
    }



    @Override
    public Class getSuportClass() {
        return OrderState.class;
    }

}
